// pages/module/rebate/rebate.js
import regeneratorRuntime from '../../../utils/runtime.js';
import img_list from '../../../utils/util.js';
import time from '../../../utils/time.js';
import { getData, setData, clearData, dataKey } from '../../../utils/storage.js';
import shareFun from '../../../utils/shareFun.js';
import {
  orderList,retXpOrder,xpOrderDetail,cancelXpOrder
} from '../../../utils/imapi.js';
import Dialog from '../../common/components/vant/dialog/dialog';
var app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    reason:{},
    showAction:false,
    reason_list:[],
    otderInfo:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad:async function (options) {
    const eventChannel = this.getOpenerEventChannel();
    let self = this;
    eventChannel.on('acceptDataFromOpenerPage',function(data) {
      self.setData({
        order_no:data.id,
      })
      xpOrderDetail({ order_id: data.id }).then(res=>{
        console.log(res.data);
        self.setData({
          orderInfo:res.data,
        })
      })
    
      
    })
    const ret = await retXpOrder()//app.globalData.uid
    console.log(ret);
    this.setData({
      reason_list:ret.data
    })
  },
  showDialog:function(){
    this.setData({
      showAction:true
    })
  },
  submit_ret:function(){
    let self = this;
    Dialog.confirm({
        title: '提示',
        message: '是否确认退款？',
      })
      .then(() => {
      
        cancelXpOrder({
          order_no: self.data.orderInfo.order_id,
          reason_info: self.data.reason.reason
        }).then(res => {
          wx.navigateBack()
        })
      })
      .catch(() => {
      
      });
  },
  onClose:function(){
    this.setData({
      showAction:false
    })
  },
  select:function(e){
    let index = e.currentTarget.dataset.index;
    this.setData({
      reason:this.data.reason_list[index],
      showAction:false
    })
  }

})